package com.platform.modules.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.common.utils.RestResponse;
import com.platform.modules.sys.service.SysUserSelectCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("sys/select")
public class SysUserSelectCourseController extends AbstractController {

    @Autowired
    private SysUserSelectCourseService selectCourseService;

    /**
    * @Description: 分页查询必选任务列表
    * @param params 查询条件
    * @return 返回分页数据结果
    * @throws
    * @author zdz
    * @date 2021/7/3 12:46
    */
    @GetMapping("/mustList")
    //@RequiresPermissions("sys:jmcourse:list")
    public RestResponse list(@RequestParam Map<String, Object> params) {
        params.put("orgNo", getOrgNo());
        Page page = selectCourseService.queryMustSelectPage(params);
        return RestResponse.success().put("page", page);
    }

    /**
    * @Description: 分页查询任选任务列表
    * @param params 查询条件
    * @return 返回分页数据结果
    * @throws
    * @author zdz
    * @date 2021/7/3 12:48
    */
    @GetMapping("/mayList")
    //@RequiresPermissions("sys:jmcourse:list")
    public RestResponse mayList(@RequestParam Map<String, Object> params) {
        params.put("orgNo", getOrgNo());
        Page page = selectCourseService.queryMaySelectPage(params);
        // 查询当前用户已经选择的任选任务id列表
        params.put("userId", getUserId());
        List<String> havaSelectMayCourseIds = selectCourseService.queryAllMayCourseIds(params);
        RestResponse rr = RestResponse.success();
        rr.put("page", page);
        rr.put("havaSelect", havaSelectMayCourseIds);
        return rr;
    }


    /**
    * @Description: 保存选择的任务列表
    * @param courseIds 选中的任选任务id
    * @return 返回保存状态信息
    * @throws
    * @author zdz
    * @date 2021/7/3 20:59
    */
    @RequestMapping("save")//, @RequestParam(name = "courseIds[]") String[] courseIds
    public RestResponse saveSelectCourse(String moduleId, String courseIds) {
        // 保存用户选课记录
        boolean status = selectCourseService.saveUserSelectCourse(getUser(), moduleId, courseIds);
        if (status) {
            return RestResponse.success();
        }
        return RestResponse.error();
    }



}
